﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HopeHealth.Domain.Services
{
    public class MediaService
    {
        public List<Entities.MediaFolder> GetFolders(Nullable<Guid> parentId)
        {
            using (HHDbContext dbContext = new HHDbContext())
            {
                EntityRepository<Entities.MediaFolder> rep = new EntityRepository<Entities.MediaFolder>(dbContext);
                return rep.GetList(p => p.ParentId == parentId);
            }
        }


        public bool CreateFolder(Nullable<Guid> parentId, string name, int creator)
        {
            using (HHDbContext dbContext = new HHDbContext())
            {
                Entities.MediaFolder mediaFolder = new Entities.MediaFolder();
                mediaFolder.Id = Guid.NewGuid();
                mediaFolder.Name = name;
                mediaFolder.CreatedTime = DateTime.Now;
                mediaFolder.Creator = creator;
                mediaFolder.IsDeleted = false;
                mediaFolder.State = 1;
                mediaFolder.ParentId = parentId;

                EntityRepository<Entities.MediaFolder> rep = new EntityRepository<Entities.MediaFolder>(dbContext);
                rep.Create(mediaFolder);

                if (dbContext.SaveChanges() > 0)
                {
                    return true;
                }
                return false;
            }
        }
    }
}
